home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 12.1 KB | 421 lines | [TEXT/MPS ] |
- /*
- • List units defining any constants, types or classes that are required for your implementation
- section (e.g. Packages or Errors)
- • Also list units defining the classes that you declared EXTERNAL in the interface section
- or wish to use in the implementation section.
- • Also list the units required by the interfaces of the above units.
- */
- #include "UTearOffMenuView.h"
-
- #ifndef __UGEOMETRY__
- #include <UGeometry.h>
- #endif
-
- #ifndef __UWindow__
- #include "UWindow.h";
- #endif
-
- #ifndef __UFailure__
- #include "UFailure.h";
- #endif
-
- #ifndef __TEXTEDIT__
- #include "TextEdit.h";
- #endif
-
- #ifndef __UMacAppUtilities__
- #include "UMacAppUtilities.h";
- #endif
-
- #ifndef __UPatch__
- #include "UPatch.h";
- #endif
-
- #ifndef __DIALOGS__
- #include "Dialogs.h";
- #endif
-
- #ifndef __UMacAppGlobals__
- #include "UMacAppGlobals.h";
- #endif
-
- #ifndef __ERRORS__
- #include "Errors.h";
- #endif
-
- #ifndef __TOOLUTILS__
- #include "ToolUtils.h";
- #endif
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffDoCommand
-
- pascal void TShowTearOffWindowCmd::Initialize(void)// override
-
- {
- inherited::Initialize();
- fTearOffWindow = NULL;
- fWhere = gZeroPt;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffDoCommand
-
- pascal void TShowTearOffWindowCmd::IShowTearOffWindowCmd(TWindow* tearOffWindow,
- Point where)
-
- {
- this->INoChangesCommand(0, NULL, NULL);
- fTearOffWindow = tearOffWindow;
- fWhere = where;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffDoCommand
-
- pascal void TShowTearOffWindowCmd::DoIt(void) // override
-
- {
- if (fTearOffWindow)
- {
- fTearOffWindow->Locate(fWhere, kDontInvalidate);// move it to its new home
- fTearOffWindow->fMustForceOnScreen = TRUE;// so the Open will call ForceOnScreen
- fTearOffWindow->fForcedOnScreen = FALSE;
- fTearOffWindow->Open(); // show the torn-off window
- fTearOffWindow->Select(); // select the torn-off window
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffFields
-
- pascal void TShowTearOffWindowCmd::Fields(TObject* obj)// override
-
- {
- obj->DoToField("TShowTearOffWindowCmd", (Ptr)NULL, bClass);
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffInit
-
- pascal void TTearOffTracker::Initialize(void) // override
-
- {
- inherited::Initialize();
- fExitTracking = FALSE;
- fOrigin = gZeroPt;
- fTearOffMenu = NULL;
- fTearOffWindowOutline = NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffInit
-
- pascal void TTearOffTracker::ITearOffTracker(Point hitPt,
- TTearOffMenuView* tearOffMenu)
-
- {
- VPoint theMouse;
-
- theMouse.v = hitPt.v;
- theMouse.h = hitPt.h;
- this->ITracker(0, NULL, NULL, NULL, theMouse);
-
- fCanUndo = FALSE;
- fCausesChange = FALSE;
- fFreeOnCompletion = FALSE;
-
- fTearOffMenu = tearOffMenu;
-
- fTearOffWindowOutline = MakeNewRgn(); // !!! needs failure handler
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffClose
-
- pascal void TTearOffTracker::Free(void) // override
-
- {
- fTearOffWindowOutline = DisposeIfRgnHandle(fTearOffWindowOutline);
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffDoCommand
-
- pascal void TTearOffTracker::DoIt(void)
-
- {
- Point where;
- TWindow * aTearOffWindow;
- TShowTearOffWindowCmd * aShowTearOffWindowCmd;
-
-
- if (!fExitTracking) /* ensure that we didn't exit the tracking
- loop */
- {
- aTearOffWindow = fTearOffMenu->fTearOffWindow;
-
- where.v = (*fTearOffWindowOutline)->rgnBBox.top + aTearOffWindow->fContRgnInset.v;
- where.h = (*fTearOffWindowOutline)->rgnBBox.left + aTearOffWindow->fContRgnInset.h;
-
- if (aTearOffWindow != NULL)
- {
- /* NOTE: we can't just move and show the tear off window here because the menu that
- we want to tearx off is currently displayed on the screen and the menu manager has
- cached the bits underneath the currently displayed menu and we might be moving our
- floating window into that territory thus invalidating the menu manager's cache (which
- the menu manager will blit back in place momentarily). To work-around this "feature"
- we'll simply post a command which will do the work later. Isn't MacApp wonderful! */
- aShowTearOffWindowCmd = new TShowTearOffWindowCmd;
- aShowTearOffWindowCmd->IShowTearOffWindowCmd(aTearOffWindow, where);
- fTearOffMenu->PostCommand(aShowTearOffWindowCmd);
- }
-
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffDoCommand
-
- pascal void TTearOffTracker::TrackFeedback(TrackPhase /* aTrackPhase */,
- const VPoint& /* anchorPoint */,
- const VPoint& /* previousPoint */,
- const VPoint& /* nextPoint */,
- Boolean mouseDidMove,
- Boolean /* turnItOn */)
- {
- if (mouseDidMove && !EmptyRgn(fTearOffWindowOutline))
- {
- PenPat(qd.gray);
- FrameRgn(fTearOffWindowOutline); // draw/erase
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffDoCommand
-
- pascal TTracker* TTearOffTracker::TrackMouse(TrackPhase aTrackPhase,
- VPoint& ,
- VPoint& previousPoint,
- VPoint& nextPoint,
- Boolean)
-
- {
- TWindow * aTearOffWindow;
- short verticalOffset;
- short horizontalOffset;
- Boolean rgnsWereBuilt;
-
- fExitTracking =!PtInRgn(Point(nextPoint), fTearOffMenu->fTearOffTrackingRgn);
-
- if (aTrackPhase == trackBegin)
- {
- aTearOffWindow = fTearOffMenu->fTearOffWindow;
- if (aTearOffWindow != NULL)
- {
- rgnsWereBuilt = aTearOffWindow->BuildWindowRgns(kBuild);
- CopyRgn(((WindowPeek)aTearOffWindow->fWMgrWindow)->strucRgn, fTearOffWindowOutline);
- aTearOffWindow->BuildWindowRgns(rgnsWereBuilt);
-
- // move the outline to the topleft of the window mgr graf port
- OffsetRgn(fTearOffWindowOutline, -(*fTearOffWindowOutline)->rgnBBox.left, -(*fTearOffWindowOutline)->rgnBBox.top);
-
- // move the outline so that it's centered at the mouse
- verticalOffset = ((*fTearOffWindowOutline)->rgnBBox.Length(vSel)) / 2;
- horizontalOffset = ((*fTearOffWindowOutline)->rgnBBox.Length(hSel)) / 2;
- OffsetRgn(fTearOffWindowOutline, (short)(previousPoint.h - horizontalOffset), (short)(previousPoint.v - verticalOffset));
- }
- //aTearOffWindow != NULL
- }
- else
- OffsetRgn(fTearOffWindowOutline, (short)(nextPoint.h - previousPoint.h), (short)(nextPoint.v - previousPoint.v));
- return this;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffDoCommand
-
- pascal Boolean TTearOffTracker::IsDoneTracking(void)// override
-
- {
- return ((!StillDown()) || fExitTracking);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MTearOffFields
-
- pascal void TTearOffTracker::Fields(TObject* obj)// override
-
- {
- obj->DoToField("TTearOffTracker", (Ptr)NULL, bClass);
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffInit
-
- pascal void TTearOffMenuView::Initialize(void) // override
-
- {
- inherited::Initialize();
- fTearOffTracker = NULL;
- fTearOffTrackingRgn = NULL;
- fTearOffWindow = NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffInit
-
- pascal void TTearOffMenuView::ITearOffMenuView(short rsrcID,
- short menuWidth,
- short menuHeight,
- TWindow* tearOffWindow)
-
- {
- this->IMenuView(rsrcID, menuWidth, menuHeight);
- fTearOffTrackingRgn = MakeNewRgn();
- fTearOffWindow = tearOffWindow;
-
- this->InstallTearOffTracker();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffInit
-
- pascal void TTearOffMenuView::InstallTearOffTracker(void)
- /* For the sake of efficiency when tracking a tear-off, we'll create the tear-off tracker and
- keep it with us, so we don't need to allocate a new tracker every time we tear off a menu. If you
- want a different tracker in your subclass of TTearOffMenuView, then override this method. */
-
- {
- TTearOffTracker * tearOffTracker;
-
- tearOffTracker = new TTearOffTracker;
- tearOffTracker->ITearOffTracker(gZeroPt, this);
- fTearOffTracker = tearOffTracker;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffClose
-
- pascal void TTearOffMenuView::Free(void) // override
-
- {
- fTearOffTracker = (TTearOffTracker *)FreeIfObject(fTearOffTracker);
- fTearOffTrackingRgn = DisposeIfRgnHandle(fTearOffTrackingRgn);
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffRes
-
- pascal void TTearOffMenuView::HandleChooseMessage(short,
- MenuHandle,
- Rect& menuRect,
- Point hitPt,
- short& whichItem)// override
-
- {
- short newItem;
- Rect hitRect;
- TToolboxEvent * event = NULL;
- EventRecord anEventRecord;
- Boolean saveTrackingInMenu;
-
-
- // so that trackers know that they're tracking in menus
- saveTrackingInMenu = gTrackingInMenu;
- gTrackingInMenu = TRUE;
-
- newItem = kNoMenuItem; // default return
-
- if (this->IsEnabled()) // menu enabled
- {
- // see if point is within hit area
- this->GetQDExtent(hitRect);
- hitRect += fBorder;
- if (hitRect.Contains(hitPt)) // in menu view (not border)
- {
- // NOTE: Either your subclass of TTearOffMenuView should override DoMouseCommand or one of
- // TTearOffMenuView's view's subview's should override DoMouseCommand so that
- // it creates and posts a TTracker. TTearOffMenuView's override of PostCommand
- // will ensure that the tracker is tracked immediately. The tracker, having
- // been posted and tracked, will then get executed next time PerformCommand is
- // called. So, when we're done with HandleMouseDown below, we simply tell the
- // menu manager that no menu item was selected, ie newItem == kNoMenuItem.
-
- event = new TToolboxEvent;
- event->IToolboxEvent(NULL);
- this->CreateMouseDownEventInfo(hitPt, anEventRecord, event);
- this->HandleMouseDown(hitPt, event, gStdHysteresis);
- event = (TToolboxEvent *)FreeIfObject(event);
- }
- else
- { /* determine if we should track a tear off
- image */
- LocalToGlobal(hitPt);
- if (PtInRgn(hitPt, this->GetTearOffTrackingRgn(menuRect)))
- {
- fTearOffTracker->fInitialPt = hitPt;
- this->PostCommand(fTearOffTracker);
- }
- }
- }
- else
- this->UpdateHighlight(whichItem, newItem); // Update highlighting
-
- gTrackingInMenu = saveTrackingInMenu;
-
- // Tell MenuManager about new item
- whichItem = newItem;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffRes
-
- pascal RgnHandle TTearOffMenuView::GetTearOffTrackingRgn(const Rect& menuRect)
- // This function returns fTearOffTrackingRgn
-
- {
- Rect rgnRect;
-
- if (EmptyRgn(fTearOffTrackingRgn))
- {
- Rect rect = menuRect;
-
- // calculate the tracking region for the tearoff image
- LocalToGlobal(rect[topLeft]);
- LocalToGlobal(rect[botRight]);
- SetRect(rgnRect, rect.left - kTearOffMargin, rect.top, rect.right + kTearOffMargin, rect.bottom + kTearOffMargin);
-
- #if qDebug
- UseTempRgn("TTearOffMenuView.HandleDefproc");
- #endif
-
- RectRgn(gTempRgn, rgnRect);
- DiffRgn(GetGrayRgn(), gTempRgn, fTearOffTrackingRgn);
- #if qDebug
- DoneWithTempRgn();
- #endif
-
- InsetRgn(fTearOffTrackingRgn, 4, 4);
- }
- return fTearOffTrackingRgn;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment TearOffFields
-
- pascal void TTearOffMenuView::Fields(TObject* obj)// override
-
- {
- obj->DoToField("TTearOffMenuView", (Ptr)NULL, bClass);
- inherited::Fields(obj);
- }
-
-
-